<template>
  <div class="app-container">
    <el-container style="height: 900px; border: 1px solid #eee; ">
      <el-aside width="250px" style="padding-left: 5px;padding-right: 5px;overflow: auto !important;">
        <!--分类树视图-->
        <zhai-tree @getNodeClick="treeHandler" ref="zhaiTree"></zhai-tree>
      </el-aside>
      <el-main>
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-select v-model="queryParams.itemId" placeholder="请选择项目" @change="itemChange" clearable size="small">
            <el-option
              v-for="dict in itemList"
              :key="dict.id+''"
              :label="dict.name"
              :value="dict.id"
            />
          </el-select>
          <el-form-item label="楼号" prop="floorId">
            <el-select v-model="queryParams.floorId" placeholder="请选择楼号" clearable size="small">
              <el-option
                v-for="dict in floorList"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="feeinfoList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="类目名称" align="center" prop="categoryName" />
          <el-table-column label="楼号" align="center" prop="floorName" />
          <el-table-column label="详细部位" align="center" prop="detailBody" />
          <el-table-column label="项目特征" align="center" prop="featureDes" />
          <el-table-column label="单位" align="center" prop="unitId">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.unit_type" :value="scope.row.unitId"/>
            </template>
          </el-table-column>
          <el-table-column label="人工费" align="center">
            <el-table-column label="单价" align="center" prop="laborPrice" >
              <template slot-scope="scope">
                <span v-if="scope.row.feeType!='2'">{{scope.row.laborPrice}}</span>
              </template>
            </el-table-column>
            <el-table-column label="工程量" align="center" prop="laborNum" >
              <template slot-scope="scope">
                <span v-if="scope.row.feeType!='2'">{{scope.row.laborNum}}</span>
              </template>
            </el-table-column>
            <el-table-column label="小计" align="center" prop="laborTotal">
              <template slot-scope="scope">
                <span v-if="scope.row.feeType!='2'">{{scope.row.laborTotal}}</span>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="材料费" align="center">
            <el-table-column label="单价" align="center" prop="materialPrice" />
            <el-table-column label="工程量" align="center" prop="materialNum" />
            <el-table-column label="小计" align="center" prop="materialTotal" />
          </el-table-column>
          <el-table-column label="机械费" align="center">
            <el-table-column label="单价" align="center" prop="machineryPrice" />
            <el-table-column label="工程量" align="center" prop="machineryNum" />
            <el-table-column label="小计" align="center" prop="machineryTotal" />
          </el-table-column>
          <el-table-column label="综合合计" align="center" prop="totalAmount">
            <template slot-scope="scope">
              <span v-if="scope.row.feeType!='2'">{{scope.row.totalAmount}}</span>
            </template>
          </el-table-column>
          <el-table-column label="备注" align="center">
            <el-table-column label="1%发票费" align="center" prop="bill1" />
            <el-table-column label="3%发票费" align="center" prop="bill3" />
            <el-table-column label="6%发票费" align="center" prop="bill6" />
            <el-table-column label="9%发票费" align="center" prop="bill9" />
            <el-table-column label="13%发票" align="center" prop="bill13" />
            <el-table-column label="普票" align="center" prop="bill" />
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-main>
    </el-container>
  </div>
</template>

<script>
import {
  listFeeinfo,
  getFeeinfo,
  delFeeinfo,
  addFeeinfo,
  updateFeeinfo,
  exportFeeinfo,
  getItem,
  getFloorList,
  getItemList
} from "@/api/feesys/feeinfo";
import { listFileinfo,deleteFile} from "@/api/feesys/fileinfo";
import ZhaiTree from '@/components/ZhaiTree'
import { getToken } from "@/utils/auth";
export default {
  name: "Feeinfo",
  dicts: ['fee_type', 'unit_type'],
  components: {
    ZhaiTree
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 费用管理表格数据
      feeinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      floorList:[],
      item:{},
      itemList:[],
      btnStatus:true,
      uploadFileDrawer:false,
      category:null,
      // 上传参数
      upload: {
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/feesys/fileinfo/upload/",
        // 上传的文件列表
        fileList: []
      },
      categoryRemark:"测试备注",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        itemId: null,
        itemName: null,
        categoryId: null,
        categoryName: null,
        ancestors: null,
        floorId: null,
        floorName: null,
        feeType: "1",
        detailBody: null,
        featureDes: null,
        unitId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        floorId: [
          { required: true, message: "请选择楼号", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getItemList();
  },
  methods: {
    /** 查询费用管理列表 */
    getList() {
      this.loading = true;
      listFeeinfo(this.queryParams).then(response => {
        this.feeinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getItemList(){
      getItemList().then(response => {
        this.itemList=response.data;
        if(this.itemList){
          this.initQuery(this.itemList[0].id);
        }
      })
    },
    getFloorList(obj){
      getFloorList(obj).then(response => {
        console.log(response)
        this.floorList=response.data;
      })
    },
    initQuery(itemId){
      this.resetQuery();
      //获取列表
      this.queryParams.itemId=itemId;
      // this.getList();
      //获取楼号
      let obj={};
      obj.itemId=itemId;
      obj.status=0;
      this.getFloorList(obj);
      //获取树结构
      this.$refs.zhaiTree.getTreeselect(itemId)
    },
    itemChange(itemId){
      if(itemId){
        this.initQuery(itemId);
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        itemId: this.form.itemId,
        itemName: this.form.itemName,
        categoryId: this.form.categoryId,
        categoryName: this.form.categoryName,
        ancestors: null,
        floorId: null,
        floorName: null,
        feeType: null,
        detailBody: null,
        featureDes: null,
        unitId: null,
        materialUnitId: null,
        machineryUnitId: null,
        laborPrice: null,
        laborNum: null,
        laborTotal: this.laborPrice*this.laborNum,
        materialPrice: null,
        materialNum: null,
        materialTotal: null,
        machineryPrice: null,
        machineryNum: null,
        machineryTotal: null,
        totalAmount: null,
        ysPrice:null,
        ysNum:null,
        ysTotal:null,
        bill1: null,
        bill3: null,
        bill6: null,
        bill9: null,
        bill13: null,
        bill: null,
        isAllPrice:0,
        allPrice:null,
        allNum:null,
        allTotal:null,
        status: "0",
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有费用管理数据项？').then(() => {
        this.exportLoading = true;
        return exportFeeinfo(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    },
    treeHandler(node) {
      this.queryParams.categoryId=null;
      this.queryParams.ancestors=node.data.id;
      this.getList();
    }
  }
};
</script>
